package com.shouer.doc.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;

import com.shouer.doc.R;
import com.shouer.doc.widget.AminalImageView;

/**
 * Created by yangyayun on 2016/12/22.
 */

public class ShouerLoadingDialog extends Dialog {

    private View mDialogView;
    private AminalImageView loadingView;

    private DialogDismissListener dialogDismissListener;

    public ShouerLoadingDialog(Context context) {
        super(context);
        init(context);
    }

    public ShouerLoadingDialog(Context context, int themeResId) {
        super(context, themeResId);
        init(context);
    }

    protected ShouerLoadingDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        init(context);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        WindowManager.LayoutParams params = getWindow().getAttributes();
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        params.width = ViewGroup.LayoutParams.WRAP_CONTENT;
        params.gravity= Gravity.CENTER;
        getWindow().setAttributes((WindowManager.LayoutParams) params);
        setCanceledOnTouchOutside(true);

    }

    private void init(Context context) {

        mDialogView = View.inflate(context, R.layout.dialog_loading, null);
        loadingView= (AminalImageView) mDialogView.findViewById(R.id.aminal_view);

        loadingView.setImageResource(R.drawable.shouer_loading);

        setCanceledOnTouchOutside(true);
        setContentView(mDialogView);
    }

    public ShouerLoadingDialog withDialogDismissListener(DialogDismissListener dialogDismissListener) {
        this.dialogDismissListener = dialogDismissListener;
        return this;
    }


    @Override
    public void dismiss() {
        super.dismiss();
        if (null != dialogDismissListener)
        {
            dialogDismissListener.onDialogDismiss();
        }
    }

}
